#include <iostream>
#include <vector>
using namespace std;

int MOD = 19650827;
pair<int, int> cal(vector<int> &nums, int l, int r, vector<vector<pair<int, int>>> &dp)
{
        if(l == r){
                return dp[l][r] = {-1, 1};
        }

        if(l + 1 == r){
                if(nums[l] < nums[r]){
                        return {1, 1};
                }else{
                        return {0, 0};
                }
        }

        if(dp[l][r] != pair<int, int>(-1, -1)){
                return dp[l][r];
        }

        auto left = cal(nums, l + 1, r, dp);
        auto right = cal(nums, l, r - 1, dp);
        int a = 0, b = 0;
        if(nums[l] < nums[l + 1]){
                a = (a + left.first)%MOD;
        }
        if(nums[l] < nums[r]){
                a = (a + left.second)%MOD;
        }
        if(nums[r] > nums[r - 1]){
                b = (b + right.second)%MOD;
        }
        if(nums[r] > nums[l]){
                b = (b + right.first)%MOD;
        }

        return dp[l][r] = {a, b};
}

int main()
{
        int n = 0;
        cin >> n;
        vector<int> nums(n, 0);
        for(int i = 0; i < n; i++){
                cin >> nums[i];
        }
        if(n == 1){
                return 1;
        }

        vector<vector<pair<int, int>>> dp(n, vector<pair<int, int>>(n, {-1, -1}));
        auto ans = cal(nums, 0, n - 1, dp);
        cout<< (ans.first + ans.second)%MOD <<endl;
        return 0;
}